home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / ODF / OS / FWGraphx / FWScrCon.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  4.0 KB  |  160 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWScrCon.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWSCRCON_H
  13. #include "FWScrCon.h"
  14. #endif
  15.  
  16. #ifndef FWODGEOM_H
  17. #include "FWODGeom.h"
  18. #endif
  19.  
  20. #ifndef SLREGION_H
  21. #include "SLRegion.h"
  22. #endif
  23.  
  24. #ifndef SOM_ODShape_xh
  25. #include <Shape.xh>
  26. #endif
  27.  
  28. #if defined(FW_BUILD_MAC) && !defined(__WINDOWS__)
  29. #include "Windows.h"
  30. #endif
  31.  
  32. #if defined(FW_BUILD_MAC) && !defined(__QUICKDRAW__)
  33. #include "QuickDraw.h"
  34. #endif
  35.  
  36. //========================================================================================
  37. //    RunTime Info
  38. //========================================================================================
  39.  
  40. #ifdef FW_BUILD_MAC
  41. #pragma segment FWGraphx_ScreenContext
  42. #endif
  43.  
  44. FW_DEFINE_AUTO(FW_CScreenContext)
  45.  
  46. //========================================================================================
  47. //    class FW_CScreenContext
  48. //========================================================================================
  49.  
  50. //----------------------------------------------------------------------------------------
  51. //    FW_CScreenContext::FW_CScreenContext
  52. //----------------------------------------------------------------------------------------
  53.  
  54. FW_CScreenContext::FW_CScreenContext(Environment* ev,
  55.                                        ODShape* clipShape,
  56.                                        ODTransform* transform) :
  57.     FW_CGraphicContext(ev),
  58.     fGraphicDevice(NULL)
  59. {
  60. #ifdef FW_BUILD_WIN
  61.     FW_PlatformCanvas aPlatformCanvas = 0;
  62. #endif
  63.     ODShape* odClipShape = NULL;
  64.  
  65.     FW_TRY
  66.     {
  67. #ifdef FW_BUILD_WIN
  68.         fDC = ::GetDC(NULL);
  69.         aPlatformCanvas = FW_PrivGDev_WinCreateFromHDC(ev, fDC);
  70.         fGraphicDevice = FW_PrivGDev_CreateFromPlatformCanvas(ev, aPlatformCanvas);
  71.         FW_FailOnEvError(ev);
  72.         
  73.         int xScreen = ::GetSystemMetrics(SM_CXSCREEN);
  74.         int yScreen = ::GetSystemMetrics(SM_CYSCREEN);
  75.  
  76.         FW_CRect rect(FW_IntToFixed(0), FW_IntToFixed(0), FW_IntToFixed(xScreen), FW_IntToFixed(yScreen));
  77.         odClipShape = ::FW_NewODShape(ev, rect);
  78. #endif
  79. #ifdef FW_BUILD_MAC
  80.         GrafPtr savePort;
  81.         ::GetPort(&savePort);
  82.         ::OpenCPort(&fCGrafPort);
  83.         ::SetPort(savePort);
  84.  
  85.         fGraphicDevice = FW_PrivGDev_CreateFromPlatformCanvas(ev, (FW_PlatformCanvas) &fCGrafPort);
  86.         FW_FailOnEvError(ev);
  87.         
  88.         ODRgnHandle grayRgnCopy = ::FW_CopyRegion(GetGrayRgn());
  89.         odClipShape = ::FW_NewODShape(ev, grayRgnCopy);
  90. #endif
  91.         
  92.         if(clipShape != NULL)
  93.             odClipShape->Intersect(ev, clipShape);
  94.     
  95.         InitGraphicContext(fGraphicDevice,
  96.                             transform,
  97.                             odClipShape);
  98.     
  99.         odClipShape->Release(ev);        // we don't need it
  100.     }
  101.     FW_CATCH_BEGIN
  102.     FW_CATCH_EVERYTHING()
  103.     {
  104.         if(odClipShape != NULL)
  105.             odClipShape->Release(ev);
  106.             
  107.         FW_PrivGDev_Release(fGraphicDevice);
  108.  
  109. #ifdef FW_BUILD_WIN
  110.         ::ReleaseDC(NULL, fDC);
  111.         delete aPlatformCanvas;
  112. #endif
  113. #ifdef FW_BUILD_MAC
  114.         ::CloseCPort(&fCGrafPort);
  115. #endif
  116.  
  117.         FW_THROW_SAME();
  118.     }
  119.     FW_CATCH_END
  120.  
  121.     FW_END_CONSTRUCTOR
  122. }
  123.  
  124. //----------------------------------------------------------------------------------------
  125. //    FW_CScreenContext::~FW_CScreenContext
  126. //----------------------------------------------------------------------------------------
  127.  
  128. FW_CScreenContext::~FW_CScreenContext()
  129. {
  130.     FW_START_DESTRUCTOR
  131.  
  132. #ifdef FW_BUILD_WIN
  133.     FW_SOMEnvironment ev;
  134.     FW_PlatformCanvas aPlatformCanvas = FW_PrivGDev_GetPlatformCanvas(fGraphicDevice);
  135. #endif
  136.  
  137.     // ----- Terminate the superclass
  138.     TerminateGraphicContext();
  139.  
  140.     // ----- Delete the device
  141.     FW_PrivGDev_Release(fGraphicDevice);
  142.  
  143.     // ----- It is now safe to clean up the platform device
  144. #ifdef FW_BUILD_WIN
  145.     ::ReleaseDC(NULL, fDC);
  146.     delete aPlatformCanvas;
  147. #endif
  148. #ifdef FW_BUILD_MAC
  149.     ::CloseCPort(&fCGrafPort);
  150. #endif
  151. }
  152.  
  153. //----------------------------------------------------------------------------------------
  154. //    FW_CScreenContext::Reset
  155. //----------------------------------------------------------------------------------------
  156.  
  157. void FW_CScreenContext::Reset()
  158. {
  159.     // Nothing to do [HLX] Am i sure ?
  160. }